﻿using Furion.DependencyInjection;
using Furion.FriendlyException;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mrhd.Core
{
    /// <summary>
    /// 异常处理日志记录
    /// </summary>
    public class LogExceptionHandler : IGlobalExceptionHandler, ISingleton
    {

        private ILogger<LogExceptionHandler> _logger;
        public LogExceptionHandler(ILogger<LogExceptionHandler> logger)
        {
            _logger = logger;
        }

        public Task OnExceptionAsync(ExceptionContext context)
        {
            // 写日志
            var content = "系统异常：" + context.Exception.Message;
            _logger.LogError(context.Exception, content);
            return Task.CompletedTask;
        }
    }
}
